package com.juyu.miliao.api.dao.mysql;

import com.juyu.miliao.api.domain.ActiveGift;
import com.juyu.miliao.api.domain.ActiveGiftRanking;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class ActiveGiftDao {
    @Resource
    private SqlSession sqlSession;

    public ActiveGift getActiveGiftSwitchInfo(String activeDate) {
        return sqlSession.selectOne("getActiveGiftSwitchInfo",activeDate);
    }

    public List<ActiveGiftRanking> getActiveGiftList(String activeDate) {
        return sqlSession.selectList("getActiveGiftList",activeDate);
    }

    public void updateActiveGiftGainNum(int activeGiftId, int giftNum) {
        Map<String, Object> params = new HashMap<>();
        params.put("activeGiftId", activeGiftId);
        params.put("giftNum", giftNum);
        sqlSession.update("updateActiveGiftGainNum",params);
    }

    public void insertActiveGiftRanking(String activeDate, long userId,String icon, String nickName, int giftNum) {
        Map<String, Object> params = new HashMap<>();
        params.put("activeDate", activeDate);
        params.put("userId", userId);
        params.put("icon",icon);
        params.put("nickName", nickName);
        params.put("giftNum", giftNum);
        sqlSession.update("insertActiveGiftRanking",params);
    }
}
